#include "net_client.h"

Netclient::Netclient()
 : toclose(false)
{
}

void Netclient::connectToServer( const std::string& hostip, int port )
{
	m_socket.open(hostip.c_str(), port);
}

void Netclient::sendMessage( const std::string& message )
{
	if ( !toclose && m_socket.send((void*)message.c_str(), message.size()) < message.size() )
		toclose = true;
	
}

void Netclient::checkIncomingMessages( std::vector<std::string>* messages )
{
	while( !toclose && m_socket.isReady() )
	{ 
		memset(buffer, 0, sizeof buffer);
		if ( m_socket.recieve( buffer, sizeof buffer) < 1 )
		{
			toclose = true;
		}
		else
			messages->push_back(std::string(buffer));
	}
}


Netclient::~Netclient()
{
	m_socket.close();
}

